// components/xuanxiangver1/optionItem.js
Component({
  /**
   * 组件的属性列表
   * index：A、B、C
   * detail：选项的题面
   */
  properties: {
    _index: String,
    detail: {
      type: String,
      value: "默认选项数据"
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    type: 'noactive'
  },

  /**
   * 组件的方法列表
   * _handleTap: 点击时抛出点击的选项的index
   */
  methods: {
    _handleTap: function(){/*自己点击的话，就只能在active和noactive之间变换*/
      console.log('in optionItem.js, before a, type=',this.data.type)
      let a = this.data.type == 'active' ? false : true
      console.log('in optionItem.js, a=',a)
      if(a == true){
        this.setData({type: 'active'})
      }else{
        this.setData({type: 'noactive'})
      }
      let i = this.data._index
      if(i == '√'){
        this.triggerEvent('tapOption', {index: 'T', isActive: a}, {bubbles: true}); //事件允许冒泡
      }else if(i == '×'){
        this.triggerEvent('tapOption', {index: 'F', isActive: a}, {bubbles: true}); //事件允许冒泡
      }else{
        this.triggerEvent('tapOption', {index: this.data._index, isActive: a}, {bubbles: true}); //事件允许冒泡
      }
    },
    _setType: function(newType){
      this.setData({type: newType})
    }
  },
  lifetimes: {
    attached: function() {
      let i = this.data._index
      if(i == '√'){
        this.triggerEvent('optionAttached', {index: 'T'}, {bubbles: true});
      }else if(i == '×'){
        this.triggerEvent('optionAttached', {index: 'F'}, {bubbles: true});
      }else{
        this.triggerEvent('optionAttached', {index: i}, {bubbles: true}); //事件允许冒泡
      }
    }
  }
})
